// TOWN SCRIPT
//    Town 7: Small town

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
	change_blocked(14,12,1);
	change_blocked(15,12,1);
	change_blocked(16,12,1);
	change_blocked(17,12,1);
	
	change_blocked(10,15,1);
	change_blocked(11,15,1);
	change_blocked(12,15,1);
	change_blocked(13,15,1);
	
	change_blocked(11,10,1);
	
	change_blocked(17,8,1);
	change_blocked(17,9,1);
	change_blocked(17,10,1);
	
	change_blocked(10,16,1);
	change_blocked(11,16,1);
	change_blocked(12,16,1);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 10;
	block_entry(1);
		move_to_new_town(9,4,8);
		end();
break;

beginstate 11;
	if (get_flag(5,3) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"7.",0);
	add_dialog_str(1,"You are in a small town. Point B is in front of you. The direct route to Point B is obstructed. You must first reach Point A to activate Point B. A hostile monster blocks the route to Point B. A guard blocks the way to Point B.",0);
	add_dialog_str(2,"It is necessary to retrieve a special item before reaching Point B. You must reach Point B. Custom graphics and terrain scripts have been implemented.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(5,3,250);
break;

beginstate 12;
	if (get_flag(1,2) >= 1)
		end();
		
	message_dialog("You have yet to activate Point B.","");
	block_entry(1);
break;

beginstate 14;
	message_dialog("You have yet to activate Point B.","");
	block_entry(1);
break;

beginstate 15;
	print_str("You activate Point B.");
	set_flag(1,2,1);
break;

beginstate 18;
	set_flag(1,2,0);
	set_state_continue(10);
break;

beginstate 19;
	if (get_flag(4,5) == 250)
		end();
	set_flag(4,5,250);
	message_dialog("The hostile monster appears.","");
	activate_hidden_group(5);
break;

beginstate 20;
	if (get_flag(2,7) == 250)
		end();
	set_flag(2,7,250);
	message_dialog("You retrieve the special item.","");
	change_spec_item(27,1);
break;

beginstate 21;
	change_spec_item(27,-1);
break;

beginstate 22;
	if (has_special_item(27) > 0)
		end();
	
	message_dialog("You do not have the special item.","");
	block_entry(1);
break;

beginstate 24;
// OBSOLETE NODE: Timers are no longer used. Manually write scenario timers in the 
// scenario script.
break;

beginstate 25;
if (char_ok(7)) {
	block_entry(1);
	message_dialog("The guard blocks your way.","");
	}
else {
	change_blocked(10,16,0);
	change_blocked(11,16,0);
	change_blocked(12,16,0);
	}
break;